/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package database;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.Product;
import model.Revenuebyproduct;

/**
 *
 * @author Trang
 */
public class MontlyReportDAO {
    private Connection con;

    public MontlyReportDAO() {
        con = DBFactory.createConnection("onlineshopping");
    }
    
    public double GetTotalCost(String month)
    {
        double result = 0;
        try
        {
            String sql ="SELECT sum(totalAmount) as totalCost from receipt Where createTime like '"+month+"%'";
            PreparedStatement ps = con.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            while(rs.next())
            {    
                double totalCost = rs.getDouble("totalCost");
                result = totalCost;
            }
        }
        catch (SQLException ex) {
            Logger.getLogger(MontlyReportDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }
    
     public double GetTotalRevenue(String month)
    {
        double result = 0;
        try
        {
            String sql ="SELECT sum(ordertb.totalAmount) as totalRenvenue from issue, ordertb Where issue.createTime like '"+month+"%' AND issue.Order_idOrder = ordertb.idOrder;";
            PreparedStatement ps = con.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            while(rs.next())
            {    
                double totalRenvenue = rs.getDouble("totalRenvenue");
                result = totalRenvenue;
            }
        }
        catch (SQLException ex) {
            Logger.getLogger(MontlyReportDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }
}
